package com.ftf.tp.user.application.dto;

import com.ftf.tp.common.core.utils.SnowIdUtils;
import com.ftf.tp.user.application.assembler.ActionAssembler;
import com.ftf.tp.user.domain.action.dos.ActionDO;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Date;

/**
 * 点赞/关注/订阅消息实体
 *
 * @author tanghao
 * @date 2021/11/28
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SupportDTO implements Serializable {
    /**
     * 目标id
     */
    @ApiModelProperty("目标id")
    private Long targetId;

    /**
     * 目标类型
     */
    @ApiModelProperty("目标类型 0:文章")
    private String targetType;

    /**
     * 取消或支持
     */
    @ApiModelProperty("取消或点赞 0点赞 1取消")
    private Integer supportType;

    /**
     * 点赞时间
     */
    private Date supportTime;

    public ActionDO toActionDO() {
        ActionDO actionDO = ActionAssembler.INSTANCE.dtoToDo(this);
        if (supportType.equals(0)) {
            actionDO.setAction("support");
        } else {
            actionDO.setAction("cancel_support");
        }
        actionDO.setCreatedTime(new Date());
        actionDO.setId(SnowIdUtils.uniqueLong());
        return actionDO;
    }
}
